package com.zl.task.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zl.task.dao.ServiceChinaMapper;
import com.zl.task.pojo.ServiceChina;
import com.zl.task.service.IServiceChinaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yinlingeng
 * @since 2021-07-26
 */
@Service
public class ServiceChinaServiceImpl extends ServiceImpl<ServiceChinaMapper, ServiceChina> implements IServiceChinaService {

    /**
     * 所有省
     *
     * @return
     */
    @Override
    public List<ServiceChina> listProvince() {
        return baseMapper.selectList(Wrappers.<ServiceChina>lambdaQuery()
                .isNull(ServiceChina::getSecondNumber));
    }

    /**
     * 所有市区
     *
     * @return
     */
    @Override
    public List<ServiceChina> listCity() {
        return baseMapper.selectList(Wrappers.<ServiceChina>lambdaQuery()
                .isNotNull(ServiceChina::getSecondNumber));
    }

    /**
     * 省份所有市区
     *
     * @param number
     * @return List<ServiceChina>
     */
    @Override
    public List<ServiceChina> listCityByProvince(String number) {
        return baseMapper.selectList(Wrappers.<ServiceChina>lambdaQuery()
                .eq(ServiceChina::getSecondNumber,number));
    }

    /**
     * 根据编号查找省市
     *
     * @param number -
     * @return String
     */
    @Override
    public String getProvince(String number) {
        return baseMapper.selectOne(Wrappers.<ServiceChina>lambdaQuery()
        .eq(ServiceChina::getNumber,number)).getName();
    }



}
